import request from '@/utils/request'

export interface PostVO {
  id?: number
  name: string
  code: string
  sort: number
  status: number
  remark: string
  createTime?: Date
}

// 查询岗位列表
export const getPostPage = async (params: any) => {
  return request({
    url: '/system/post/page',
    method: 'GET',
    params,
  })
}

// 获取岗位精简信息列表
export const getSimplePostList = async (): Promise<PostVO[]> => {
  return request({
    url: '/system/post/simple-list',
    method: 'GET',
  })
}

// 查询岗位详情
export const getPost = async (id: number) => {
  return request({
    url: `/system/post/get?id=${id}`,
    method: 'GET',
  })
}

// 查询岗位排序号
export const getPostSort = async () => {
  return request({
    url: `/system/post/getSort`,
    method: 'GET',
  })
}

export const saveOrUpdate = async (data: PostVO) => {
  if (data.id !== 0 && data.id) {
    return request({
      url: '/system/post/update',
      method: 'PUT',
      data,
    })
  } else {
    return request({
      url: '/system/post/create',
      method: 'POST',
      data,
    })
  }
}
// 新增岗位
export const createPost = async (data: PostVO) => {
  return request({
    url: '/system/post/create',
    method: 'POST',
    data,
  })
}

// 修改岗位
export const updatePost = async (data: PostVO) => {
  return request({
    url: '/system/post/update',
    method: 'PUT',
    data,
  })
}

// 删除岗位
export const deletePost = async (id: number) => {
  return request({
    url: `/system/post/delete?id=${id}`,
    method: 'DELETE',
  })
}

// 导出岗位
export const exportPost = async (params) => {
  return request({
    url: '/system/role/export-excel',
    method: 'GET',
    responseType: 'blob',
    params,
  })
}
